<?php $auth=0; ?>
<?php include 'lib/includes.php'; ?>
<?php include 'partials/header_menu.php'; ?>
<?php 
$select=$db->query('select societeId,societeNom,societeRef,societeDetails from societe');
$socs=$select->fetchAll();

/**
*suppression
**/
if(isset($_GET['delete']))
{
	$id=$db->quote($_GET['delete']);
	$db->query("delete from societe where societeId=$id");
	header('Location: /prescription/company.php');
	die();
}
?>
<br>
<br>
<h3>&nbsp;&nbsp;La liste des sociétés</h3>
<br>
<p>&nbsp;&nbsp;&nbsp;<a href="company_edit.php" class="btn btn-success">ajouter une nouvelle société&nbsp;<span  class="glyphicon glyphicon-plus"></span></a><p>
<center>
<div id="grid" style="width: 100%; height: 380px;"></div>
	<script>var i=0;</script>
	<?php  foreach($socs as $soc){ 
	//echo json_encode($soc); 
	?>
	<script>
	var sup='<a href="company_edit.php?id=<?php echo($soc['societeId']); ?>" class="glyphicon glyphicon-edit">&nbsp;editer</a>&nbsp;&nbsp;<a href="company.php?delete=<?php echo($soc['societeId']); ?>" class="glyphicon glyphicon-remove" onclick="">&nbsp;supprimer</a>';
	i++;
	$('#grid').w2grid({
    name: 'grid',
    header: 'Liste des sociétés',
    show: {
        toolbar: true,
        footer: true
    },
    columns: [
        { field: 'recid', caption: 'ID', size: '30px', sortable: true, attr: 'align=center' },
        { field: 'fname', caption: 'ID du sociétété', size: '20%', sortable: true, resizable: true },
		{ field: 'lname', caption: 'Nom de la société', size: '30%', sortable: true, resizable: true },
        { field: 'email', caption: 'Réference du société', size: '30%', resizable: true },
        { field: 'sdate', caption: 'Autres informations', size: '30%', resizable: true },
		{ field: 'link', caption: 'Action', size: '30%', resizable: true },
    ],
    searches: [
        { field: 'lname', caption: 'Nom de la société', type: 'text' },
        { field: 'fname', caption: 'ID du sociétété', type: 'text' },
        { field: 'email', caption: 'Réference du société', type: 'text' },
    ],
    sortData: [{ field: 'recid', direction: 'ASC' }]
    });
	w2ui['grid'].add({ recid:  i , fname: <?php echo($soc['societeId']); ?> , lname: '<?php echo($soc['societeNom']); ?>', email: '<?php echo($soc['societeRef']); ?>', sdate: '<?php echo($soc['societeDetails']); ?>',link:sup });
	</script>
	<?php }?>	
</center>
<br>
<?php include 'partials/footer.php'; ?>
